

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

import persistence.DAO.FactoryDB;
import client.interfaces.ClientRemoteMgt;
import employee.interfaces.EmployeeRemoteMgt;
import article.interfaces.ArticleRemoteMgt;
import sale.interfaces.SaleRemoteMgt;
import service.article.ArticleRemoteMgr;
import service.client.ClientRemoteMgr;
import service.employee.EmployeeRemoteMgr;
import service.sale.SaleRemoteMgr;

public class Main {

	public static void main(String[] args) throws RemoteException {

		String articleName = FactoryDB.getInstance().getArticle();
		String saleName = FactoryDB.getInstance().getSale();
		String clientName = FactoryDB.getInstance().getClient();
		String employeeName = FactoryDB.getInstance().getEmployee();
		
		
		ArticleRemoteMgr oArticle = ArticleRemoteMgr.getInstance(); 
		ArticleRemoteMgt oStub = (ArticleRemoteMgt) UnicastRemoteObject
				.exportObject(oArticle,0);
		
		SaleRemoteMgr oSale = SaleRemoteMgr.getInstance();
		SaleRemoteMgt oSaleStub = (SaleRemoteMgt) UnicastRemoteObject.exportObject(oSale,0);
		
		ClientRemoteMgr oClient = ClientRemoteMgr.getInstance();
		ClientRemoteMgt oClientStub = (ClientRemoteMgt) UnicastRemoteObject.exportObject(oClient,0);
		
		EmployeeRemoteMgr oEmployee = EmployeeRemoteMgr.getInstance();
		EmployeeRemoteMgt oEmployeeStub = (EmployeeRemoteMgt) UnicastRemoteObject.exportObject(oEmployee,0);
		
		Registry oRegistry = LocateRegistry.createRegistry(FactoryDB.getInstance().getPort());
		
		oRegistry.rebind(articleName, oStub);
		oRegistry.rebind(saleName, oSaleStub);
		oRegistry.rebind(clientName, oClientStub);
		oRegistry.rebind(employeeName, oEmployeeStub);
		
		
		System.out.println("Ready and waiting");
		
	}

}